package com.liang.lessonIp;

import javax.swing.text.StyledEditorKit;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class TcpClientDemo2 {
    public static void main(String[] args) throws IOException {
        //1.我有一个地址
            ServerSocket serverSocket = new ServerSocket(9999);
       //2.等待客户端链接
        Socket accept = serverSocket.accept();
        //3.读取客户端信息
        InputStream is = accept.getInputStream();

        //管道流
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = is.read(buffer))!=-1){
            baos.write(buffer,0,len);
        }
        System.out.println(baos.toString());

        //关闭资源
        is.close();
        accept.close();
        serverSocket.close();
        baos.close();

    }
}
